import {request} from '../../utils/http'

Page({
  data: {},
  onLoad() {},
  getPhoneNumber() {
    const ext = my.getExtConfigSync()
    my.getPhoneNumber({
      // protocols: {
      //   isvAppId: '2021003144609376'
      // },
      success: (res) => {
        let response = JSON.parse(res.response);
        console.log(response);
        if (response.response.code) {
          my.showToast({content: response.response.subMsg})
          return;
        }
        my.getAuthCode({
          scopes: 'auth_base',
          success: ({ authCode }) => {
            request('/alipay/get_mobile', 'post', {
              encryptedData: response.response,
              authCode
            }).then(res2 => {
              console.log(res2)
              if  (res2.code == 200) {
                this.setData({
                  member: {
                    ...res2.data
                  }
                })
      
                my.setStorage({
                  key: 'userInfo',
                  data: {
                    ...res2.data
                  },
                  success: function() {
                    console.log('缓存写入成功')
                  }
                })
      
                my.navigateBack();
              }
             
              
            })
          },
        })
        
      },
      fail: (res) => {
        console.log(res);
        console.log('getPhoneNumber_fail');
      },
    });
  },
  onAuthError(err) {
    console.log(err);
  },
});
